<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>宜鲜生</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <!-- load css -->
    <link rel="stylesheet" type="text/css" href="../css/bootstrap.min.css?v=v3.3.7" media="all">
    <link rel="stylesheet" type="text/css" href="../css/font/iconfont.css?v=1.0.0" media="all">
    <link rel="stylesheet" type="text/css" href="../css/layui.css?v=1.0.9" media="all">
    <link rel="stylesheet" type="text/css" href="../css/main.css?v1.3.4" media="all">
    <link rel="stylesheet" type="text/css" href="../asset/treegrid/jquery.treegrid.css">
    <link rel="stylesheet" type="text/css" href="../css/autocomplete.css" media="all">

</head>
<div class="container-fluid larry-wrapper">
    <div class="row">
        <div class="col-xs-12 col-sm-12 col-md-12">

            <!--列表-->
            <section class="panel panel-padding">
                <div class="group-button">
                    <button class="layui-btn layui-btn-small modal-catch" beforeFun="beforeAdd"
                            data-params='{"content":".add-subcat", "title":"添加","type":"1", "area":"[680px,600px]"}'>
                        <i class="iconfont">&#xe649;</i> 添加
                    </button>

                </div>
                <div id="list" class="layui-form"></div>
            </section>
        </div>
    </div>
</div>

    <table id="treeGrid" class="layui-table lay-even tree">
        <thead>
            <tr>
                <!--<th width="30"><input type="checkbox" id="checkall" data-name="checkbox" lay-filter="check"
                                      lay-skin="primary"></th>-->
                <th name="name">名称</th>
                <th name="icon" type="icon" height="30">图标</th>
                <th name="operator">状态</th>
                <th name="ord" width="80">排序</th>
                <th width="200" type="operate">操作</th>
            </tr>
        </thead>
        <tbody></tbody>
    </table>
<script type="text/javascript" src="../js/lib/rest.js"></script>
<script type="text/javascript" src="../js/lib/jquery-1.11.2.min.js"></script>
<script type="text/javascript" src="../asset/treegrid/jquery.treegrid.js"></script>
<script type="text/javascript" src="../js/lib/bootstrap.autocomplete.js"></script>
<script src="../js/layui/layui.js"></script>
<script type="text/javascript" src="../js/lib/treetable.js"></script>
<!--#include file="category-form.html"-->
<!--#include file="common/version.html"-->
<script>
    TreeTable.initTableData('/education/admin/category/treeData');

    function del(ids){
        layer.confirm('确认 <span style="color:red">删除</span> 操作吗?',  {icon: 3, title:'提示'}, function(index){
            restPost('/education/admin/category/delete/' + ids, {'id': ids}, function(rs){
               if(rs.status == 200){
                   location.reload();
               } else {
                    layer.msg(rs.msg);
               }
            });
            layer.close(index);
        });
    }

    function update(ids){
        if(ids){
            $('.add-subcat #form1').attr('action', '/education/admin/category/update/' + ids);
            restGet('/education/admin/category/view/' + ids, null, $('#form1'), function(rs){
                var index =  layer.open({
                    type: 1,
                    content: $('.add-subcat'),
                    "title": "编辑", "area":"[650px,600px]", "maxmin":"true"
                });
                layer.full(index);
            });
        } else {
            var index = layer.open({
                type: 1,
                content: $('.add-subcat'),
                "title": "添加", "area":"[650px,600px]", "maxmin":"true"
            });
            layer.full(index);
        }
    }

    function _editTd(obj){
        var v = $(obj).text();
        $(obj).parent().html('<input type="text" class="layui-input" onblur="_updateTd(this);" value="'+ v +'">');
    }

    function _updateTd(obj){
        var k = $(obj).parent().attr('name');
        var ids = $(obj).parent().attr('ids');
        var v = $(obj).val();

        var p = {};
        p[k] = v;
        $(obj).parent().html('<a href="#" onclick="_editTd(this);">'+ v +'</a>');

        restPost('/education/admin/category/updateOptional/' + ids, p, function(rs){
            if(rs.status == 200){
                location.reload();
                layer.msg(rs.msg ? rs.msg : '修改成功');
            } else {
                layer.msg(rs.msg ? rs.msg : '修改失败');
            }
        })

    }

    function beforeAdd(){
        $('input[name=ids]').val('');
        $('#form1').attr('action', "/education/admin/category/save");
    }
</script>